import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    token: localStorage.getItem('token') || '',
    role: localStorage.getItem('userRole') || ''
  }),
  actions: {
    setToken(newToken, newRole) {
      this.token = newToken
      this.role = newRole
      localStorage.setItem('token', newToken)
      localStorage.setItem('userRole', newRole)
    },
    logout() {
      this.token = ''
      this.role = ''
      localStorage.removeItem('token')
      localStorage.removeItem('userRole')
    }
  }
})；